$(function () {
    getUserInfo();

    function getUserInfo() {
        axios({
            method: 'GET',
            url: '/my/userinfo',

            // headers: {
            //     Authorization:localStorage.getItem('token')
            // }
        }).then(res => {
            // console.log(res)
            if (res.data.status !== 0) {
                return layui.layer.msg(res.data.message)
            }

            renderAvatar(res.data.data)
        });
    }

    function renderAvatar(user) {
        let name = user.nickname || user.username
        $(".welcome").html('欢迎&nbsp' + name);
        if (user.user_pic !== null) {
            $(".avatar-text").hide();
            $(".layui-nav-img").show().attr('src', user.user_pci);
        } else {

            $('.layui-nav-img').hide();

            let first = name[0].toUpperCase();
            $(".avatar-text").show().html(first)
        }
    }

    // 退出
    $("#logout").on('click', function () {
        layer.confirm('确认退出登录吗?', { icon: 3, title: '提示' }, function (index) {

            location.href = '/login.html';
            localStorage.removeItem('token');
            layer.close(index)
        })

    })

})



